package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemRoleButtonInsertRequestDTO;
import com.example.child_protection.dto.request.find.SystemRoleButtonRequestDTO;
import com.example.child_protection.dto.request.update.SystemRoleButtonUpdateRequestDTO;
import com.example.child_protection.dto.response.SystemRoleButtonListResponseDTO;
import com.example.child_protection.dto.response.SystemRoleButtonResponseDTO;
import com.example.child_protection.service.SystemRoleButtonManageService;
import com.example.child_protection.service.SystemRoleButtonQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 角色按钮权限管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("systemRoleButton")
@Api(value = "/api-systemRoleButton", description = "角色按钮权限管理")
public class SystemRoleButtonController extends BaseController {

    @Autowired
    public SystemRoleButtonManageService systemRoleButtonManageService;

    @Autowired
    public SystemRoleButtonQueryService systemRoleButtonQueryService;

    @ApiOperation(value ="查询角色按钮权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemRoleButtonResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        logger.info("用户ID{},sessionId{}",request.getSession().getAttribute("user"),request.getSession().getId());
        SystemRoleButtonResponseDTO responseDTO = systemRoleButtonQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询角色列表按钮权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemRoleButtonListResponseDTO findList(SystemRoleButtonRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        SystemRoleButtonListResponseDTO responseDTO = systemRoleButtonQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加角色按钮权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(SystemRoleButtonInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleButtonManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改角色按钮权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(SystemRoleButtonUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleButtonManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除角色按钮权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleButtonManageService.delete(requestDTO);
        return responseDTO;
    }

}
